(31337_29435797471674, `[large]Overview[/large]
The point of an assembly language is to give human readable nicknames to the instructions that computers execute.

The assembly syntax here follows general conventions, so you should be able to read assembly from most real CPUs after you learn these.

Instruction syntax begins with an abbreviated word, called a "[color=#9966ff]mnemonic[/color]", which describes the instruction. It is followed by a list of [color=#66ccff]operands[/color], like so:[box][color=#9966ff]mov[/color] [color=#66ccff]r1[/color], [color=#66ccff]4[/color][/box]

Assembly programs are mostly just lists of instructions.

[large]Operands[/large]

There are several types of [color=#66ccff]operands[/color].

[b]Registers[/b]
In the above example [color=#66ccff]r1[/color] is replaced with 1 in the generated machine code.

[b]Numbers[/b]
In the above example [color=#66ccff]4[/color] is inserted directly into the machine code.

[b]Labels[/b]
For jump instructions, you generally want to reference offsets in the generated machine code. These offsets can be automatically calculated for you using labels: [box][color=#9966ff]jmp[/color] [color=#66ccff]my_label[/color]
...
[color=#66ccff]my_label:[/color][/box]
Labels are always declared by adding a name on a line with a colon after it.


[large]Other features[/large]

[b]Comments[/b]
Everything on the same line after [highlight];[/highlight] is considered a comment and ignored by the assembler, like so:
[box][color=#eeeeee]mov r1, 123 [/color][color=#999999]; Moving 123 into register 1[/color]
[/box]

[b]Raw data[/b]
You can insert data directly in between the assembled instructions like so:
[highlight]U8 123[/highlight]
Here we insert the byte 123. [highlight]U8[/highlight] means "unsigned 8 bit value", but the assembler also supports [highlight]U16[/highlight], [highlight]U32[/highlight] and [highlight]U64[/highlight].
You can also insert the value of ASCII characters like so:
[highlight]"Hello"[/highlight]

[b]const[/b]
Create new names for your registers or other operand types like this:
[highlight]const ROTATION = r0[/highlight]
In this example [highlight]ROTATION[/highlight] becomes an alternative name for r0. Creating local names for your registers can make your code easier to read.

[b]Sections[/b]
Insert an [highlight]@[/highlight] with an address to make the assembler to insert zeroes until it reaches that address. For example:
[highlight]@0x800[/highlight]

[b]Include[/b]
You can include other assembly files, for example including "std_lib.asm" from the parent folder:
[highlight]include ../std_lib[/highlight]

Including another assembly file will insert its assembled result where the include is placed. You can also use the labels and 'set' names defined in the included file, if they are exposed in their file by being prefixed by the 'pub' keyword, like so:
[highlight]pub print:[/highlight]

To access an exposed name or label, put the file name and a dot before the name, like so:
[highlight]jmp std_lib.print[/highlight]
Using this you can create a library of functions that can be called from any level. Just put the library file in the folder above the levels and expose the labels that correspond to each function.`)
